package com.battle.service.controller.web;

import com.battle.pojo.param.carWarCase.GetCarWarCaseListParam;
import com.battle.pojo.param.trainingAchievement.EditTrainingAchievementParam;
import com.battle.pojo.param.trainingAchievementDetails.*;
import com.battle.pojo.vo.trainingAchievementDetails.*;
import com.battle.service.service.in.*;
import jakarta.servlet.http.HttpServletResponse;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.exceptions.BizException;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;

/**
 * web/培训成绩/个人培训成绩
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/trainingAchievementDetails/web")
public class TrainingAchievementDetailsWebController {

    private final TrainingAchievementDetailsService service;

    public TrainingAchievementDetailsWebController(TrainingAchievementDetailsService service) {
        this.service = service;
    }

    /**
     * 修改个人培训成绩
     *
     * @param param
     * @return
     */
    @PostMapping("/editTrainingAchievementDetails")
    public ApiResult editTrainingAchievementDetails(@RequestBody @Valid EditTrainingAchievementDetailsParam param) {
        service.editTrainingAchievementDetails(param);
        return ApiResult.ok();
    }


    /**
     * 获取个人培训成绩详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getTrainingAchievementDetails")
    public ApiResult<GetTrainingAchievementDetailsVo> getTrainingAchievementDetails(@RequestParam("id") Long id) {
        GetTrainingAchievementDetailsVo vo = service.getTrainingAchievementDetails(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取个人培训成绩列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getTrainingAchievementDetailsList")
    public ApiResult<PageResult<GetTrainingAchievementDetailsListVo>> getTrainingAchievementDetailsList(@RequestBody GetTrainingAchievementDetailsListParam param) {
        PageResult<GetTrainingAchievementDetailsListVo> result = service.getTrainingAchievementDetailsList(param);
        return ApiResult.ok(result);
    }

    /**
     * 导出训练考核
     * @param response
     * @param param
     */
    @PostMapping(value = "/exportTrainingAchievementDetailsList")
    public void exportTrainingAchievementDetailsList(HttpServletResponse response, @RequestBody GetTrainingAchievementDetailsListParam param) {
        try {
            service.export(param, response);
        } catch (IOException e) {
            throw new BizException(e.getMessage());
        }
    }

}

